package com.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Constants {

	public static final boolean USE_HIBERNATE = true;	
	public static final boolean DO_GUID_INSERTS = true; // false will doautoIncrement inserts.
	public static final int NO_OF_THREADS = 5;
	public static final int NO_OF_RECORDS_TO_INSERT_PER_THREAD = 1;
	public static final boolean USE_JAVA_GUID_GENERATOR = true;// true is applicable only if DO_GUID_INSERTS is also true.
	public static final String DB_URL = "jdbc:mysql://localhost:3306/test?";
	public static final String DB_CLASS = "com.mysql.jdbc.Driver";

	/* //Without department_id
	public static final String guidQuery = "insert into test.employee_guid (id, fname, lname, age, insertedby) values (uuid(), 'john', 'mirage', 20, ?)";
	public static final String javaGuidQuery = "insert into test.employee_guid (id, fname, lname, age, insertedby) values (?, 'john', 'mirage', 20, ?)";
	public static final String autoIncrementQuery = "insert into test.employee_auto (fname, lname, age, insertedby) values ('john', 'mirage', 20, ?)";
	*/
	
	//With department_id
	public static final String guidQuery = "insert into test.employee_guid (id, fname, lname, age, insertedby, department_id) values (uuid(), 'john', 'mirage', 20, ?, 'bda0cef0-8773-11e0-bac3-000c29eaeb1f')";
	public static final String javaGuidQuery = "insert into test.employee_guid (id, fname, lname, age, insertedby, department_id) values (?, 'john', 'mirage', 20, ?, 'bda0cef0-8773-11e0-bac3-000c29eaeb1f')";
	public static final String autoIncrementQuery = "insert into test.employee_auto (fname, lname, age, insertedby, department_id) values ('john', 'mirage', 20, ?, 'bda0cef0-8773-11e0-bac3-000c29eaeb1f')";

	public static String sql;

	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");

			if (DO_GUID_INSERTS) {
				if (USE_JAVA_GUID_GENERATOR)
					sql = javaGuidQuery;
				else
					sql = guidQuery;
			}

			else
				sql = autoIncrementQuery;

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static Connection getConnection() {
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(DB_URL, "root", "");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	public static void closeConnection(Connection conn) {
		try {
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}
}
